package in.freshstart.java.training.arrays;

public class ArrayExerQuickSort {
	public static int[] quickSort(int array[], int low, int n) {
		int lo = low;
		int hi = n;
		if (lo >= hi) {
//			System.out.println("please give proper array to sort");
			return null;
		}
		int mid = array[(lo + hi) / 2];
		while (lo < hi) {
			while (lo < hi && array[lo] < mid) {
				lo++;
			}
			while (lo < hi && array[hi] > mid) {
				hi--;
			}
			if (lo < hi) {
				int T = array[lo];
				array[lo] = array[hi];
				array[hi] = T;
			}
		}
		if (hi < lo) {
			int T = hi;
			hi = lo;
			lo = T;
		}
		quickSort(array, low, lo);
		quickSort(array, lo == low ? lo + 1 : lo, n);
//		System.out.print("array after sorting"+array);
		return array;
	}
	

}
